package jhta;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;

public class MyTableRender  {
	JTable table;
	char[] align;// l=left, c=center, r=right;
	int[] width;
	public MyTableRender(JTable t, char[] c, int[] w){
		DefaultTableCellRenderer render;
		this.table = t;
		this.align = c;
		this.width = w;
		
		TableColumnModel model = table.getColumnModel();
		for(int i=0; i<align.length ; i++){
			render = new DefaultTableCellRenderer();
			switch(align[i]){
			case 'l':
				render.setHorizontalAlignment(JLabel.LEFT);
				model.getColumn(i).setCellRenderer(render);
				model.getColumn(i).setPreferredWidth(width[i]);
				break;
			case 'c':
				render.setHorizontalAlignment(JLabel.CENTER);
				model.getColumn(i).setCellRenderer(render);
				model.getColumn(i).setPreferredWidth(width[i]);
				break;
			case 'r':
				render.setHorizontalAlignment(JLabel.RIGHT);
				model.getColumn(i).setCellRenderer(render);
				model.getColumn(i).setPreferredWidth(width[i]);
				break;
				
			}
		}
	}

}
